package cglgu.trellis.chado.das2.modelimpl.cglgu;

/*
 * $Id: ChadoVersion.java 191 2011-03-27 00:38:22Z sundaram.georgetown@gmail.com $
 * $Author: sundaram.georgetown@gmail.com $
 * $Date: 2011-03-27 00:38:22 +0000 (Sun, 27 Mar 2011) $
 * $Rev: 191 $
 * $HeadURL: http://genomancer.googlecode.com/svn/branches/gu-dev-branch/tengcha/src/cglgu/trellis/chado/das2/modelimpl/cglgu/ChadoVersion.java $
 */

import genomancer.trellis.das2.model.Das2SourceI;
import genomancer.trellis.das2.model.Das2VersionI;
import genomancer.vine.das2.client.modelimpl.Das2Version;
import cglgu.trellis.chado.das2.modelimpl.ChadoVersion;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashSet;
import java.util.Set;
import java.util.regex.Pattern;


public class ChadoVersion extends cglgu.trellis.chado.das2.modelimpl.ChadoVersion  {

	static boolean DEBUG = false;
	static boolean TESTING = false;
	static Pattern split_table_pattern = Pattern.compile("^chr.+_(random_)?");
	static Set tables_to_test = new HashSet();

	static {
		tables_to_test = new HashSet();
		tables_to_test.add("refGene");  // GENEPRED
		tables_to_test.add("chr10_mrna");  // PSL & split
		tables_to_test.add("firstEF");  // BED6
	}

	String name;
	/*
	 *  id is a relative URI based on name, just with spaces substituted with underscores
	 *  Currently in the CHADO database all names should just be ASCII a-zA-Z0-9 chars, but 
	 *      doing space substitution just in case
	 */
	String id;  
	String chado_description;
	String nibPath;
	String organism;
	String defaultPos;
	int active;
	int orderKey;
	String genome;
	String scientificName;
	String htmlPath;
	int hgNearOk;
	int hgPbOk;
	String sourceName;
	String clade;
	int priority;
	ChadoSource chado_source;  // inheriting Das2Source source from Das2Version
	boolean types_initialized = false;
	boolean segs_initialized = false;

	/**
	 * 
	 * @param rs ResultSet from hgcentral dbDb and genomeClade table join
	 *  
	 * select * from dbDb, genomeClade where 
	 *          dbDb.genome = genomeClade.genome 
	 *     and  dbDb.active = 1 
	 *     order by dbDb.orderKey";

	 * 
	 */
	public ChadoVersion(ChadoSource chadoSource, String name, String genome) throws SQLException { 
		
		super(chadoSource,               // source
				name.replace(' ', '_'),  // local_uri_string
				name,                    // title
				(genome + ", " + description),   // description
				("http://genome.chado.edu/cgi-bin/cglGateway?org=" + genome + "&db=" + name), // info_url
				null,        // creation_date
				null         // last_modified_date
		);       

		this.name = name;  
		this.id = name.replace(' ', '_');
		this.chado_description = description;  // used to construct DAS2 description
		//nibPath = rs.getString("nibPath");
		this.organism = genome;  
		//defaultPos = rs.getString("defaultPos");
		active = 1;
		orderKey = 1;
		genome = genome;  // used to construct DAS2 description
		//scientificName = rs.getString("scientificName");  // used to construct DAS2 description
		//htmlPath = rs.getString("htmlPath");  // can be used to construct info_url?
		//hgNearOk = rs.getInt("hgNearOk");
		//hgPbOk = rs.getInt("hgPbOk");
		sourceName = description; //rs.getString("sourceName");  // used to construct DAS2 description
		//clade = rs.getString("clade");
		priority = 1;
		this.chado_source = chadoSource; 
		//	source.addVersion(this);
	}

}